package com.longcai.utils.fuyoupay;

import com.longcai.constants.SplitConstant;

/***
 *
 *富友 响应参数验签
 *
 */
public class ResponseCheckSigna {

    /**
     * @param respCode
     * @param respDesc
     * @param mchntTCd
     * @param mchntTxnSsn
     * @return
     */
    public static String common(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn) {
        String str = respCode + "|" + respDesc + "|" + mchntTCd + "|" + mchntTxnSsn;
        return str;
    }

    /**
     * 获取企业注册（包含个人/小微企业）响应签名
     *
     * @param respCode    响应码
     * @param respDesc    响应消息
     * @param mchntTCd    商户代码
     * @param mchntTxnSsn 商户流水号
     * @param loginId     用户id
     * @param backSigna
     * @return
     */
    public Boolean responseAddUserSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String loginId, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + loginId;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 获取银行卡变更响应签名
     *
     * @param respCode    响应码
     * @param respDesc    响应消息
     * @param mchntTCd    商户代码
     * @param mchntTxnSsn 商户流水号
     * @param backSigna
     * @return
     */

    public Boolean responseCommonSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn);
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 获取分账导入响应签名
     *
     * @param respCode    响应码
     * @param respDesc    响应消息
     * @param mchntTCd    商户代码
     * @param mchntTxnSsn 商户流水号
     * @param splitSsn    分账编号
     * @param backSigna
     * @return
     */
    public Boolean responseFzImportSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String splitSsn, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + splitSsn;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 获取提现响应签名
     *
     * @param respCode    响应码
     * @param respDesc    响应消息
     * @param mchntTCd    商户代码
     * @param mchntTxnSsn 商户流水号
     * @param loginId     用户登录id
     * @param amt         提现金额
     * @param backSigna
     * @return
     */
    public Boolean responseCathSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String loginId, String amt, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + loginId + "|" + amt;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 获取网银充值响应签名
     *
     * @param respCode    响应码
     * @param respDesc    响应消息
     * @param mchntTCd    商户代码
     * @param mchntTxnSsn 商户流水号
     * @param loginId     用户登录id
     * @param amt         充值金额
     * @param backSigna
     * @return
     */
    public Boolean responseNetRechargeSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String loginId, String amt, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + loginId + "|" + amt;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 获取线上支付响应签名
     *
     * @param respCode     响应码
     * @param respDesc     响应消息
     * @param mchntTCd     商户代码
     * @param mchntTxnSsn  商户流水号
     * @param sessionId    会话标识（	预支付交易会话标识, 富友返回微信生成的预支付回话标识，用于后续接口调用中使用，该值有效期为 2 小时）
     * @param qrCode       二维码链接
     * @param subAppid     子商户公众号id
     * @param subOpenid    子商户用户标识
     * @param sdkAppid     公众号id
     * @param sdktimesTamp 时间戳
     * @param sdkNoncestr  随机字符串
     * @param sdkPackage   扩展字段（订单性情拓展字符串）
     * @param sdkPartnerid （商户身份标识）订单类型为 APP 时返回
     * @param mchntTxnNum  支付订单号
     * @param sdkSignType  签名方式
     * @param backSigna
     * @return
     */
    public Boolean responseLineRechargeSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String sessionId, String qrCode, String subAppid, String subOpenid, String sdkAppid, String sdktimesTamp, String sdkNoncestr, String sdkPackage, String sdkPartnerid, String mchntTxnNum, String sdkPaySign, String sdkSignType, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + sessionId + "|" + qrCode + "|" + subAppid + "|" +
                subOpenid + "|" + sdkAppid + "|" + sdktimesTamp + "|" + sdkNoncestr + "|" + sdkPackage + "|" + sdkPartnerid + "|" +
                mchntTxnNum + "|" + sdkPaySign + "|" + sdkSignType;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 获取普通支付响应签名
     *
     * @param paymentType 支付类型
     * @param mchntTxnNum 原请求流水号商户端唯一标识当天不能重复（自然日）
     * @param smsCode     验证码
     * @param mchntCd     商户代码
     * @param mchntTxnSsn 商户流水号
     * @param ver         接口版本号
     * @param backSigna
     * @return
     */
    public Boolean responseCommonPaySign(String paymentType, String mchntTxnNum, String smsCode, String mchntCd, String mchntTxnSsn, String ver, String backSigna) {
        String Secret2 = paymentType + "|" + mchntTxnNum + "|" + smsCode + "|" + mchntCd + "|" + mchntTxnSsn + "|" + ver;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 退款响应签名
     *
     * @param respCode    响应码
     * @param respDesc    响应消息
     * @param mchntTCd    商户代码
     * @param mchntTxnSsn 商户流水
     * @param refundFee
     * @param refundTime  退款时间
     * @param balance     原支付订单余额
     * @param backSigna
     * @return
     */
    public Boolean responseRefundSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String refundFee, String refundTime, String balance, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + refundFee + "|" + refundTime + "|" + balance;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }


    /**
     * 微信订单查询响应签名
     *
     * @param respCode     响应码
     * @param respDesc     响应流水
     * @param mchntTCd     商户代码
     * @param mchntTxnSsn  商户流水
     * @param orderAmt     订单金额
     * @param orderType    订单类型
     * @param mchntOrderNo 商户订单号
     * @param transStat    交易金额
     * @param backSigna
     * @return
     */
    public Boolean responseWeiXinOrderSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String orderAmt, String orderType, String mchntOrderNo, String transStat, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + orderAmt + "|" + orderType + "|" + mchntOrderNo + "|" + transStat;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }

    /**
     * 余额查询响应签名
     *
     * @param respCode    响应码
     * @param respDesc    响应流水
     * @param mchntTCd    商户代码
     * @param mchntTxnSsn 商户流水
     * @param loginId     用户id
     * @param ctBalance   账面总余额
     * @param caBalance   可用余额
     * @param cfBalance   冻结余额
     * @param cuBalance   未转结余额
     * @param backSigna
     * @return
     */
    public Boolean responseBalanceSearchSign(String respCode, String respDesc, String mchntTCd, String mchntTxnSsn, String loginId, String ctBalance, String caBalance, String cfBalance, String cuBalance, String backSigna) {
        String Secret2 = ResponseCheckSigna.common(respCode, respDesc, mchntTCd, mchntTxnSsn) + "|" + loginId + "|" + ctBalance + "|" + caBalance + "|" + cfBalance + "|" + cuBalance;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }


    /**
     * 支付密码修改签名
     *
     * @param mchntCd       商户代码
     * @param loginId       用户id（用户登录账号）
     * @param pageNotifyUrl 后台返回地址
     * @param ver           接口版本号
     * @param backSigna
     * @return
     */
    public Boolean responseChangePwSign(String mchntCd, String loginId, String pageNotifyUrl, String ver, String backSigna) {
        String Secret2 = mchntCd + "|" + loginId + "|" + pageNotifyUrl + "|" + ver;
        boolean b = FuiouRsaCipher.verifySign(SplitConstant.PUB_SIGN_KEY, Secret2, backSigna);
        return b;
    }
}
